use "$project_path/data/4_regdata/regdata", clear

** Appendix Figure E.8(a)

rdrobust std_diff_m1_accountability runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot std_diff_m1_accountability runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-.6(0.2).6, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Government accountability index", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E9a.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.8(b)

gen mstd_diff_m1_ex_corruption = -std_diff_m1_ex_corruption

rdrobust mstd_diff_m1_ex_corruption runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot mstd_diff_m1_ex_corruption runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-.6(0.2).6, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("(Minus) Executive corruption index", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E9b.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.8(c)

gen mstd_diff_m1_pub_corruption = -std_diff_m1_pub_corruption

rdrobust mstd_diff_m1_pub_corruption runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot mstd_diff_m1_pub_corruption runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-.6(0.2).6, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("(Minus) Public sector corruption index", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E9c.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.8(d)

rdrobust std_diff_m1_control_corruption runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot std_diff_m1_control_corruption runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-.6(0.2).6, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Control of corruption index", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E9d.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.8(e)

egen diff_m1_chix_corruption = rowmean(std_diff_m1_accountability mstd_diff_m1_ex_corruption mstd_diff_m1_pub_corruption std_diff_m1_control_corruption)

rdrobust diff_m1_chix_corruption runvar
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot diff_m1_chix_corruption runvar if inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-.6(0.2).6, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Absence of corruption index", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E9e.pdf", as(pdf) name("Graph") replace

